package com.gitee.client;

import com.gitee.enums.ResponseEnum;
import com.gitee.exception.CartException;
import com.gitee.sdk.CartSDK;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@FeignClient(name = "canteen-wx-cookbook", fallback = CartClient.CartClientFallBack.class)
public interface CartClient {

    @GetMapping("/client/cart")
    List<CartSDK> listCarts(Integer userId, Integer cookbookId, Integer cookbookType);

    @DeleteMapping("/client/cart")
    void removeCart(Integer userId, Integer foodId, Integer cookbookId, Integer cookbookType);

    @Component
    static class CartClientFallBack implements CartClient {

        @Override
        public List<CartSDK> listCarts(Integer userId, Integer cookbookId, Integer cookbookType) {
            throw new CartException(ResponseEnum.ERROR);
    }

        @Override
        public void removeCart(Integer userId, Integer foodId, Integer cookbookId, Integer cookbookType) {
            throw new CartException(ResponseEnum.ERROR);
        }
    }
}
